local yinghun = fk.CreateSkill {

  name = "joy__yinghun",

  tags = {  },

}



yinghun:addEffect(fk.EventPhaseStart, {
  name = "joy__yinghun",
  anim_type = "control",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(yinghun.name) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local to
    if player:getLostHp() > 0 then
      to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#joy__yinghun-discard:::"..player:getLostHp(), yinghun.name, true)
    else
      to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#joy__yinghun-drawcard", yinghun.name, true)
    end
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function (self,event,target,player,data)
    local p = player.room:getPlayerById(event:getCostData(self))
    if not p.dead then
      player.room:drawCards(p,1,yinghun.name)
    end
    if not p.dead and player:getLostHp() > 0 then
      player.room:askForDiscard(p,player:getLostHp(),player:getLostHp(),true,yinghun.name,false)
    end
  end
})

return yinghun